// fileName      :  api_error.go
// createdAt     :  2021-10-19
// description   :

package my_error

type MyError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func NewMyError(code int) *MyError {
	return &MyError{
		Code:    code,
		Message: getMsg(code),
		Data:    nil,
	}
}

//NewMyErrorCustomer 自定义错误码和消息
func NewMyErrorCustomer(code int, msg string) *MyError {
	return &MyError{
		Code:    code,
		Message: msg,
	}
}

func (this *MyError) Error() string {
	return this.Message
}

func (this *MyError) SetErrCode(code int) *MyError {
	return &MyError{
		Code:    code,
		Message: getMsg(this.Code),
		Data:    this.Data,
	}
}

func (this *MyError) SetData(data interface{}) *MyError {
	return &MyError{
		Code:    this.Code,
		Message: getMsg(this.Code),
		Data:    data,
	}
}

func (this *MyError) Response() *MyError {
	return &MyError{
		Code:    this.Code,
		Message: getMsg(this.Code),
		Data:    this.Data,
	}
}
